import Vue from 'vue'
import Vuex from 'vuex'
// 导入本地保存模块
import { getItem, setItem } from '../utils/storage.js'
Vue.use(Vuex)
// 声明一个常量 token
const TOKEN_KEY = 'TOUTIAO_USER'
export default new Vuex.Store({
  state: {
    user: getItem(TOKEN_KEY)
  },
  mutations: {
    setUser (state, user) {
      state.user = user
      // 保存到本地
      setItem(TOKEN_KEY, user)
    }
  },
  actions: {
  },
  modules: {
  }
})
